package logic

import (
	"context"
	"zg1/weipinhui/models/mysql"

	"zg1/weipinhui/wphrpc/internal/svc"
	"zg1/weipinhui/wphrpc/wphrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PreferLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPreferLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreferLogic {
	return &PreferLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PreferLogic) Prefer(in *wphrpc.PreferRequest) (*wphrpc.PreferResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{}
	mysql.DB.Where("id=?", in.Id).Find(&user)

	user.Age = in.Age
	user.Ads = in.Ads
	user.Email = in.Email
	user.Image = in.Image

	mysql.DB.Updates(&user)

	return &wphrpc.PreferResponse{
		Id: int64(user.ID),
	}, nil
}
